class Apple
{
	private:
		coordList *appleBody;
	public:
		coordList *firstPrevState;
		coordList *secondPrevState;

		Apple( void )
		{
			appleBody = new coordList;

			appleBody->x = 5;
			appleBody->y = 5;
			appleBody->z = 5;

			appleBody->nextPtr = NULL;
		}
		~Apple( void )
		{
			delete appleBody;
			delete firstPrevState;
			delete secondPrevState;
		}

		(coordList *) giveApple( void );
		void respawn( coordList *snakeBody );
		int coordinateTaken( coordList *snakeBody );
};

coordList * Apple::giveApple()
{
	return appleBody;
}

void Apple::respawn( coordList *snakeBody )
{
	do
	{
		appleBody->x = rand() % 16;
		appleBody->y = rand() % 16;
		appleBody->z = rand() % 16;
	}
	while( coordinateTaken( snakeBody ) );

	dispObj.addElementToScreen( appleBody, firstPrevState, secondPrevState );

}

int Apple::coordinateTaken( coordList *snakeBody )
{
	if( appleBody->x == snakeBody->x && appleBody->y == snakeBody->y && appleBody->z == snakeBody->z )
	{
		return 1;
	}

	if( snakeBody->nextPtr != NULL )
	{
		return coordinateTaken( snakeBody->nextPtr );
	}
	else
	{
		return 0;
	}
}